package com.ruoyi.web.controller.classSeat;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.web.domain.ClassSeat;
import com.ruoyi.web.service.IClassSeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *  Controller
 *
 *
 * @date 2022-03-09
 */
@RestController
@RequestMapping("/system/seat")
public class ClassSeatController extends BaseController
{
    @Autowired
    private IClassSeatService classSeatService;
    @Resource
    private ISysDeptService sysDeptService;

    /**
     * 查询
     */
    @PreAuthorize("@ss.hasPermi('system:seat:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassSeat classSeat)
    {
        startPage();
        List<ClassSeat> list = classSeatService.selectClassSeatList(classSeat);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:seat:allList')")
    @GetMapping("/allList")
    public TableDataInfo allList(ClassSeat classSeat)
    {
        startPage();
        List<ClassSeat> list = classSeatService.allSelectList(classSeat);
        return getDataTable(list);
    }

    /**
     * 查询
     */
    @PreAuthorize("@ss.hasPermi('system:seat:seatList')")
    @GetMapping("/seatList")
    public TableDataInfo listSeat(ClassSeat classSeat)
    {
        startPage();
        List<ClassSeat> list = classSeatService.selectClassSeatList(classSeat);
        return getDataTable(list);
    }

    /**
     * 导出 列表
     */
    @PreAuthorize("@ss.hasPermi('system:seat:export')")
    @Log(title = " ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassSeat classSeat)
    {
        List<ClassSeat> list = classSeatService.selectClassSeatList(classSeat);
        ExcelUtil<ClassSeat> util = new ExcelUtil<ClassSeat>(ClassSeat.class);
        util.exportExcel(response, list, " 数据");
    }

    /**
     * 获取 详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:seat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(classSeatService.selectClassSeatById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('system:seat:add')")
    @Log(title = " ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassSeat classSeat)
    {
        return toAjax(classSeatService.insertClassSeat(classSeat));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:seat:edit')")
    @Log(title = " ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassSeat classSeat)
    {
        return toAjax(classSeatService.updateClassSeat(classSeat));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:seat:remove')")
    @Log(title = " ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classSeatService.deleteClassSeatByIds(ids));
    }


    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:seat:selectid')")
    @Log(title = "部门选择框", businessType = BusinessType.DELETE)
    @GetMapping("/selectid")
    public AjaxResult selectEditId() {
        System.out.println("请求");
        return AjaxResult.success(sysDeptService.selectDeptList(new SysDept()));
    }
}
